Passed
Pull Request — master (#47)
by
unknown
05:23
created

util.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap util.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6 View Code Duplication
(function (global, factory) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
8
  typeof define === 'function' && define.amd ? define(['jquery'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Util = factory(global.jQuery));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
16
  /**
17
   * --------------------------------------------------------------------------
18
   * Bootstrap (v4.6.0): util.js
19
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
20
   * --------------------------------------------------------------------------
21
   */
22
  /**
23
   * ------------------------------------------------------------------------
24
   * Private TransitionEnd Helpers
25
   * ------------------------------------------------------------------------
26
   */
27
28
  var TRANSITION_END = 'transitionend';
29
  var MAX_UID = 1000000;
30
  var MILLISECONDS_MULTIPLIER = 1000; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
31
32
  function toType(obj) {
33
    if (obj === null || typeof obj === 'undefined') {
34
      return "" + obj;
35
    }
36
37
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
38
  }
39
40
  function getSpecialTransitionEndEvent() {
41
    return {
42
      bindType: TRANSITION_END,
43
      delegateType: TRANSITION_END,
44
      handle: function handle(event) {
45
        if ($__default['default'](event.target).is(this)) {
46
          return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
47
        }
48
49
        return undefined;
50
      }
51
    };
52
  }
53
54
  function transitionEndEmulator(duration) {
55
    var _this = this;
56
57
    var called = false;
58
    $__default['default'](this).one(Util.TRANSITION_END, function () {
59
      called = true;
60
    });
61
    setTimeout(function () {
62
      if (!called) {
63
        Util.triggerTransitionEnd(_this);
64
      }
65
    }, duration);
66
    return this;
67
  }
68
69
  function setTransitionEndSupport() {
70
    $__default['default'].fn.emulateTransitionEnd = transitionEndEmulator;
71
    $__default['default'].event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
72
  }
73
  /**
74
   * --------------------------------------------------------------------------
75
   * Public Util Api
76
   * --------------------------------------------------------------------------
77
   */
78
79
80
  var Util = {
81
    TRANSITION_END: 'bsTransitionEnd',
82
    getUID: function getUID(prefix) {
83
      do {
84
        prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
85
      } while (document.getElementById(prefix));
86
87
      return prefix;
88
    },
89
    getSelectorFromElement: function getSelectorFromElement(element) {
90
      var selector = element.getAttribute('data-target');
91
92
      if (!selector || selector === '#') {
93
        var hrefAttr = element.getAttribute('href');
94
        selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
95
      }
96
97
      try {
98
        return document.querySelector(selector) ? selector : null;
99
      } catch (_) {
100
        return null;
101
      }
102
    },
103
    getTransitionDurationFromElement: function getTransitionDurationFromElement(element) {
104
      if (!element) {
105
        return 0;
106
      } // Get transition-duration of the element
107
108
109
      var transitionDuration = $__default['default'](element).css('transition-duration');
110
      var transitionDelay = $__default['default'](element).css('transition-delay');
111
      var floatTransitionDuration = parseFloat(transitionDuration);
112
      var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
113
114
      if (!floatTransitionDuration && !floatTransitionDelay) {
115
        return 0;
116
      } // If multiple durations are defined, take the first
117
118
119
      transitionDuration = transitionDuration.split(',')[0];
120
      transitionDelay = transitionDelay.split(',')[0];
121
      return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
122
    },
123
    reflow: function reflow(element) {
124
      return element.offsetHeight;
125
    },
126
    triggerTransitionEnd: function triggerTransitionEnd(element) {
127
      $__default['default'](element).trigger(TRANSITION_END);
128
    },
129
    supportsTransitionEnd: function supportsTransitionEnd() {
130
      return Boolean(TRANSITION_END);
131
    },
132
    isElement: function isElement(obj) {
133
      return (obj[0] || obj).nodeType;
134
    },
135
    typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
136
      for (var property in configTypes) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
137
        if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
138
          var expectedTypes = configTypes[property];
139
          var value = config[property];
140
          var valueType = value && Util.isElement(value) ? 'element' : toType(value);
141
142
          if (!new RegExp(expectedTypes).test(valueType)) {
143
            throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
144
          }
145
        }
146
      }
147
    },
148
    findShadowRoot: function findShadowRoot(element) {
149
      if (!document.documentElement.attachShadow) {
150
        return null;
151
      } // Can find the shadow root otherwise it'll return the document
152
153
154
      if (typeof element.getRootNode === 'function') {
155
        var root = element.getRootNode();
156
        return root instanceof ShadowRoot ? root : null;
0 ignored issues
show
Bug introduced by
The variable ShadowRoot seems to be never declared. If this is a global, consider adding a /** global: ShadowRoot */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
157
      }
158
159
      if (element instanceof ShadowRoot) {
160
        return element;
161
      } // when we don't find a shadow root
162
163
164
      if (!element.parentNode) {
165
        return null;
166
      }
167
168
      return Util.findShadowRoot(element.parentNode);
169
    },
170
    jQueryDetection: function jQueryDetection() {
171
      if (typeof $__default['default'] === 'undefined') {
172
        throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.');
173
      }
174
175
      var version = $__default['default'].fn.jquery.split(' ')[0].split('.');
176
      var minMajor = 1;
177
      var ltMajor = 2;
178
      var minMinor = 9;
179
      var minPatch = 1;
180
      var maxMajor = 4;
181
182
      if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
183
        throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0');
184
      }
185
    }
186
  };
187
  Util.jQueryDetection();
188
  setTransitionEndSupport();
189
190
  return Util;
191
192
})));
193
//# sourceMappingURL=util.js.map
194